import request from '@/utils/request'

export async function login(data: defs.backend.LoginPasswordRequest) {
  return request<{
    token: string
  }>({
    url: '/api/auth/loginByPassword',
    method: 'post',
    data,
  })
}

export function getUserInfo() {
  return request<defs.backend.User>({
    url: '/api/user/profile',
    method: 'get',
  })
}

export function putUserInfo(data: any) {
  return request({
    url: `/api/user/${data.id}`,
    method: 'put',
    data,
  })
}

export function logout() {
  return request({
    url: '/logout',
    method: 'get',
  })
}

export function registerApi(data: any) {
  return request({
    url: '/api/auth/registerByMobile',
    method: 'post',
    data,
  })
}

export function sendSmsCode(params: any) {
  return request({
    url: '/api/sms/sendSmsCode',
    method: 'get',
    params,
  })
}

export function smsTestCodeApi(data: any) {
  return request({
    url: '/api/sms/test',
    method: 'post',
    data,
    withCredentials: true,
  })
}
// 修改密码验证手机号
export function sendSmsCodeVerify(data: any) {
  return request({
    url: '/api/auth/forgetPassword/verify',
    method: 'post',
    data,
  })
}
// 修改密码
export function PasswordUpdate(data: any) {
  return request({
    url: '/api/auth/forgetPassword/update',
    method: 'post',
    data,
  })
}

// 换绑手机号验证
export function changeMobilVerify(data: any) {
  return request({
    url: '/api/auth/changeMobile/verify',
    method: 'post',
    data,
  })
}

// 换绑手机号
export function changeMobilUpdate(data: any) {
  return request({
    url: '/api/auth/changeMobile/update',
    method: 'post',
    data,
  })
}

export function EditPassword(data: any) {
  return request({
    url: '/api/auth/forgetPassword/update',
    method: 'post',
    data,
  })
}

export function uploadSpectrumOssPut(data: any) {
  return request({
    url: '/api/ossPut',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    method: 'post',
    data,
  })
}

// 修改密码
export function changePassword(data: any) {
  return request({
    url: '/api/auth/password',
    method: 'put',
    data,
  })
}

// 隐私协议
export function privacyAgreement() {
  return request({
    url: '/api/mp/file',
    method: 'get',
  })
}

// 获取7天天气
export const getWeatherDayApi = (location: string) => {
  return request({
    method: 'GET',
    url: `/api/h5/weatherDay/${location}`,
  })
}
